#include "fwStringHelper.h"
#include "fwLog.h"

StringHelper::StringHelper()
{

}

StringHelper::~StringHelper()
{

}

char** StringHelper::NewStringArray(FWuint count, ...)
{
	char** output = new char*[count];
	char* value; //Leak ?
	va_list marker;
	va_start(marker, count);
	int size = 0;
	for (FWuint i = 0; i < count; i++)
	{
		value = va_arg(marker, char*);
		size = strlen(value) + 1;
		output[i] = new char[size];
		strcpy(output[i], value);
	}
	va_end(marker);

	return output;
}

char** StringHelper::CpyStringArray(char** src, FWuint target, FWuint size)
{
	char** des = new char*[size];
	for (FWuint i = target; i < target + size; i++)
	{
		int strSize = strlen(src[i]) + 1;
		des[i] = new char[strSize];
		strcpy(des[i], src[i]);
	}
	return des;
}

char* StringHelper::SumString(char* strFront, char* strBehind)
{
	int sizeF = strlen(strFront);
	int sizeB = strlen(strBehind);
	char* out = new char[sizeF + sizeB + 1];
	strcpy(out, strFront);
	strcpy(out + sizeF, strBehind);
	return out;
}